﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using UnityEngine.EventSystems;

// 处理点击场景逻辑
public class TouchScene
{
    public Action<RaycastHit> OnTouchSthInScene;

    // 把点击UI上面Touch层的事件响应，放在此类处理

    // 加载点击场景预制体
    public void Init()
    {
        var obj = UIManager.Instance.AddUI("Prefabs/UI/FightUI/TouchScene", UILayer.Touch);

        var touch = obj.GetComponent<Touch>();
        touch.OnPointerDownCallback = onPointerDown;
    }

    private void onPointerDown(PointerEventData eventData)
    {
        Ray ray = CameraControl.Instance.GetComponent<Camera>().ScreenPointToRay(eventData.position);

        RaycastHit ret;
        if (Physics.Raycast(ray, out ret))
        {

            if (OnTouchSthInScene != null)
            {
                OnTouchSthInScene(ret);
            }
        }
    }
}
